@REM collect network status [ping/trace], and upload to ftpserver

@set LOCALIP=%1%
@set TARGETIP=%2%
@set TMPFOLDER=%TEMP%

@echo "usage: network_probe localip targetip"
@echo "       change the script ftp FTPURL, FTPUSER, FTPPASS"

@set FTPURL=ftp.cloudwww-demo1.com
@set FTPUSER=hntest
@set FTPPASS=forhntest

@echo off

@echo "This script would collect network status [ping/trace], and upload to ftpserver"
@echo "ctrl+c to terminate the script"
@echo ""

if "%LOCALIP%" == "" set /p LOCALIP=Please_Input_Local_Network_IP(public IP, should be ping-able):
if "%TARGETIP%" == "" set /p TARGETIP=Please_Input_Target_Network_IP(public IP, should be ping-able):



@echo ""
@echo "Testing network status from %LOCALIP% to %TARGETIP%, using ping and tracert"
@echo "Result would upload to ftp://%FTPUSER%:%FTPPASS%@%FTPURL%"


@set FTPTMP=ftpcmd.txt

@set CMD_PING=ping
@set CMD_TRACE=tracert

@set TIMESTAMP=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
@set TIMESTAMP=%TIMESTAMP: =0%

@echo ""
@echo "local timestamp is %TIMESTAMP%" 

@REM FILENAME= LOCALIP__TARGETIP__METHOD__TIMESTAMP.txt

@set "LIP=%LOCALIP:.=_%"
@set "TIP=%TARGETIP:.=_%"

@set PING_FILENAME="%LIP%__%TIP%__PING__%TIMESTAMP%.txt"
@set TRACE_FILENAME="%LIP%__%TIP%__TRACE__%TIMESTAMP%.txt"


@REM collect testing data
@echo ""
@echo "Sending 100 ping packects"
@ping -n 100 %TARGETIP% > %TMPFOLDER%/%PING_FILENAME%

@echo ""
@echo "Traceing route"
@tracert -d %TARGETIP% > %TMPFOLDER%/%TRACE_FILENAME%

@REM send testing data

@echo ""
@echo "Sending report"
@echo open %FTPURL% >%FTPTMP%
@echo   >>%FTPTMP%
@echo user %FTPUSER% %FTPPASS% >>%FTPTMP%
@echo put "%TMPFOLDER%/%TRACE_FILENAME%" >>%FTPTMP%
@echo put "%TMPFOLDER%/%PING_FILENAME%" >>%FTPTMP%
@echo quit >>%FTPTMP%

@ftp -i -s:%FTPTMP%


@REM clear file
@echo ""
@echo "Clearing temp file"

@del "%TMPFOLDER%/%PING_FILENAME%"
@del "%TMPFOLDER%/%TRACE_FILENAME%"
@del "%FTPTMP%"

@echo ""
@echo "Done! Thanks for your help. script would quit after 10 second"

@ping -n 10 127.0.0.1>nul



